/**----------------------------------------
 * @description log 基类
 * @author      lxc
 * @file        LogClass.ts
 * @Date        2022-05-05
 * @version     1.0.0
 * ----------------------------------------
 */

export class LogClass {
    /**
     * 输出log 前缀
     */
    protected logPrefix: string = "";

    private logstr: string = ""

    setPrefix(prefix : string){
        this.logPrefix = prefix
    }

    printLog(str: string, ...args: any) {
        if (CC_DEBUG) {
            this.logstr = this.logPrefix;
            this.doPrint(str, ...args)
        }
    }

    printError(str: string, ...args: any) {
        if (CC_DEBUG) {
            this.logstr = "***[ERROR]***" + this.logPrefix;
            this.doPrint(str, ...args)
        }
    }

    printWarn(str: string, ...args: any){
        if (CC_DEBUG) {
            this.logstr = "**[WARN]** " + this.logPrefix;
            this.doPrint(str, ...args)
        }
    }
    /**
     * 非调试状态也会打印的日志
     * @param str 
     * @param args 
     */
    awaysPrint(str: string, ...args: any){
        this.logstr = "[AWAYS_PRINT] " + this.logPrefix;
        this.doPrint(str, ...args)
    }

    doPrint(str: string, ...args: any) {
        this.logstr = this.logstr + " : " + str + " " + args.join(" ")
        console.log(this.logstr);
    }
}
